class Solution:
    def twoCitySchedCost(self, costs: List[List[int]]) -> int:
        costs.sort(key=lambda x: x[0] - x[1])
        n = len(costs) // 2  # 必须用//否则是float
        nsum = 0
        for i in range(n):
            nsum = nsum + costs[i][0] + costs[i+n][1]
        return nsum


# 贪心算法的运用